<template>
  <router-view/>
</template>

<script>
export default {
  name: 'App',

  //刷新页面时保存store状态数据
  created() {
    let state = sessionStorage.getItem("state");
    if (state) {
      this.$store.replaceState(
        Object.assign(this.$store.state, JSON.parse(state))
      );
      sessionStorage.clear();
    }
  },

  mounted() {
    window.addEventListener("beforeunload", () => {
      sessionStorage.setItem("state", JSON.stringify(this.$store.state));
    });
  },
  beforeDestroy() {
    window.removeEventListener("beforeunload");
  }
}
</script>

